package com.cn.zengzeng.spbzengzeng.singleton.dto1;

/**
 * 饿汉式 线程安全的
 * @Author: ZhangZengZeng
 * @Date: 2023/3/18 15:09
 */
public class SingletonDemo {


    private static final SingletonDemo SINGLETON_DEMO;
    static {
        SINGLETON_DEMO = new SingletonDemo();
    }

    private SingletonDemo(){

    }
    public static SingletonDemo getInstance(){
        return  SINGLETON_DEMO ;
    }


    public static void main (String[] args) throws InterruptedException {
        for(int i = 0;i < 30;i++) {
            new Thread(()-> {
                    SingletonDemo instance = getInstance();
                    System.out.println("instance = " + instance);
            }).start();
        }

    }
}
